<?php
/**
 * @package framework
 */

class MediaSwf extends File implements MediaInterface
{

	public $name = "";
	private $_config;

	public function setConfig($opts)
	{
		$this->_config = $opts;
	}

    public function getSize()
    {
        return $this->fileSize();
    }

	public function getType()
	{
		return $this->_config['type'];
	}

	public function getDimensions()
	{
		return $this->_config['width']." x ".$this->_config['height'];
	}

	public function load() {}
	public function printHTMLThumb() {}
    public function printHTML() 
	{
		return $this->getHTML();
	}

	public function isValidExtension($filePost)
	{
		// Chequeo extension:
		$ext = strtolower(pathinfo($filePost['name'], PATHINFO_EXTENSION));
		if(!in_array($ext, array( $this->_config['type'] )))
		{
			$this->_error("The file uploaded must be a ".$this->_config['type']." file.");
			return false;
		}

		return true;

	}

	public function update($filePost)
	{
		if (!$this->isValidExtension($filePost))
			return $this->_error($this->getErrorMessage());

		

		// I catch the posted file
		if ($this->catchPost($filePost)!=UPLOAD_ERR_OK)
			return $this->_error($this->getErrorMessage());

		// I see if the posted file is ok and a supported file format
		if (!$this->savePost())
			return $this->_error($this->getErrorMessage());

		return true;

	}

    public function getHTML($class="content")
    {
        if($this->exists())
        {

			$contentUrl = $this->getUrl();
            $contentUrlACCode = str_replace(".swf", "", $contentUrl);

            /*
            $out .= '<!--[if !IE]> -->'."\n";
            $out .= '<object type="application/x-shockwave-flash" data="'. $contentUrl .'" width="'. $this->_config['width'] .'" height="'. $this->_config['height'] .'">'."\n";
            $out .= '<!-- <![endif]-->'."\n";
            $out .= '<!--[if IE]>'."\n";
            $out .= '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="'. $this->_config['width'] .'" height="'. $this->_config['height'] .'">'."\n";
            $out .= '<param name="movie" value="'. $contentUrl .'" />'."\n";
            $out .= '<param name="loop" value="true" />'."\n";
            $out .= '<param name="menu" value="false" />'."\n";
            $out .= '<param name="wmode" value="transparent">';
            $out .= '</object>'."\n";
            $out .= '<![endif]-->'."\n";
            */

            $out .= '<script type="text/javascript">'."\n";
            $out .= "AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','". $this->_config['width']  ."','height','". $this->_config['height'] ."','src','". $contentUrlACCode ."','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','wmode','opaque','movie','". $contentUrlACCode ."'); //end AC code";
            $out .= '</script>'."\n";
            $out .= '<noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="'. $this->_config['width'] .'" height="'. $this->_config['height'] .'">'."\n";
            $out .= '<param name="movie" value="'. $contentUrl .'" />'."\n";
            $out .= '<param name="quality" value="high" />'."\n";
            $out .= '<param name="wmode" value="opaque">'."\n";
            $out .= '<embed src="'. $contentUrl .'" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'. $this->_config['width'] .'" height="'. $this->_config['height'] .'" wmode="opaque"></embed>'."\n";
            $out .= '</object></noscript>';
        }
        return $out;
    }
}
?>
